﻿namespace Topics.Radical
{
	using System;
	using System.Runtime.Serialization;
	using System.Security;

	/// <summary>
	/// Represents a weak reference, which references an object while still allowing
	/// that object to be reclaimed by garbage collection.
	/// </summary>
	/// <typeparam name="T">The type of the object that is referenced.</typeparam>
#if !SILVERLIGHT
	[Serializable]
#endif
	public class WeakReference<T> : WeakReference where T : class
	{
		/// <summary>
		/// Initializes a new instance of the WeakReference{T} class, referencing
		/// the specified object.
		/// </summary>
		/// <param name="target">The object to reference.</param>
		public WeakReference( T target )
			: base( target )
		{

		}

		/// <summary>
		/// Initializes a new instance of the WeakReference{T} class, referencing
		/// the specified object and using the specified resurrection tracking.
		/// </summary>
		/// <param name="target">An object to track.</param>
		/// <param name="trackResurrection">Indicates when to stop tracking the object. 
		/// If true, the object is tracked
		/// after finalization; if false, the object is only tracked 
		/// until finalization.</param>
		public WeakReference( T target, bool trackResurrection )
			: base( target, trackResurrection )
		{

		}

#if !SILVERLIGHT

		/// <summary>
		/// Initializes a new instance of the <see cref="WeakReference&lt;T&gt;"/> class.
		/// </summary>
		/// <param name="info">An object that holds all the data needed to serialize or deserialize the current <see cref="T:System.WeakReference"/> object.</param>
		/// <param name="context">(Reserved) Describes the source and destination of the serialized stream specified by <paramref name="info"/>.</param>
		/// <exception cref="T:System.ArgumentNullException">
		/// 	<paramref name="info"/> is null.
		/// </exception>
		protected WeakReference( SerializationInfo info, StreamingContext context )
			: base( info, context )
		{
 
		}

#endif
		
		/// <summary>
		/// Gets or sets the object (the target) referenced by the 
		/// current WeakReference{T} object.
		/// </summary>
		public new T Target
		{
			get { return ( T )base.Target; }
			set { base.Target = value; }
		}
	} 
}
